<template>
	<view class="wrap">
		<ul class="tabs-ul">
			<li class="tabs-ul-li" :class="{active:index==activeTab}" v-for="(item, index) in tabs" :key="index"
				@click="changeTab(index)">{{ item }}</li>
		</ul>
		<view class="contacts-cont" v-if="activeTab==0">
			<view class="contacts-item u-flex u-flex-between">
				<view class="telnum">已绑定手机号:19936603166</view>
				<view class="change-btn"  @tap="goPage('/pages/uc/bindTelnum')">更换</view>
			</view>
			<view class="contacts-item u-flex u-flex-between">
				<view class="telnum">公开联系</view>
				<u-switch v-model="value" @change="change" active-color="#e16b8c"></u-switch>
			</view>
		</view>
		<view class="contacts-cont" v-if="activeTab==1">
			<view class="contacts-item u-flex u-flex-between">
				<view class="telnum">微信号</view>
				<input placeholder="请输入你的微信号" placeholder-class="placeholderClass" />
			</view>
			<view class="contacts-item u-flex u-flex-column">
				<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
					:maxCount="1" width="150" height="150">
				</u-upload>
				<u-button color="#f56c6c" class="save-btn">保存微信号及名片</u-button>
			</view>
			<view class="explain-box">
				<view class="explain-title u-flex">
					<view class="line"></view>
					<text>温馨提示</text>
				</view>
				<view class="explain-cont">
					<view class="explain-text">
						1、可在档案中留下联系方式，让更多人直接联系你，有助于提高成功率
					</view>
					<view class="explain-text">
						2、被搜索时排名靠前
					</view>
					<view class="explain-text">
						3、解锁“我的-收藏-收藏我的”功能
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeTab:0, // 当前活跃的选项卡ID
				tabs: ["手机号码", "微信联系"],
				value: false,
				fileList1: [],
			}
		},
		methods: {
			changeTab(inedx) {
				this.activeTab = inedx
			},
			change(e) {
				console.log('change', e);
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style lang="less">
	.tabs-ul {
		display: flex;
		flex-direction: row;
		list-style: none;
		height: 65rpx;
		line-height: 65rpx;
		text-align: center;
		margin: 0;
		padding: 0;
		justify-content: center;
		border-bottom: 1rpx solid #eee;
		padding-bottom: 20upx;

		.tabs-ul-li {
			width: 200upx;
			height: 60upx;
			line-height: 60upx;
			text-align: center;
			border-radius: 10upx;
			font-size: 28upx;
			border-top-left-radius: 0;
		}

		.active {
			background-color: #e16b8c;
			color: #fff;
		}
	}

	.contacts-cont {
		padding: 0 30upx;

		.contacts-item {
			align-items: center;
			border-bottom: 1rpx solid #eee;
			padding: 30upx 0;

			.telnum {
				font-size: 28upx;
			}

			.change-btn {
				height: 50upx;
				line-height: 50upx;
				width: 100upx;
				text-align: center;
				background: #e16b8c;
				color: #fff;
				font-size: 28upx;
				border-radius: 10upx;
			}

			input {
				text-align: right;
				font-size: 28upx;
			}

			.save-btn{
				margin-top: 20upx;
			}
		}
	}
	.explain-box{
		padding: 30upx 0;
		.explain-title{
			font-size: 30upx;
			font-weight: bold;
			align-items: center;
			.line{
				width: 6upx;
				height: 26upx;
				border-radius: 50upx;
				background-color: #f56c6c;
				margin-right: 10upx;
			}
		}
		.explain-cont{
			margin-top: 10upx;
			.explain-text{
				line-height: 50upx;
				font-size:28upx;
			}
		}
	}
</style>